package edu.corn.job.core.parser;

import edu.corn.job.core.processor.ScheduleJobProcessor;
import jakarta.xml.bind.annotation.XmlRootElement;
import lombok.Data;

import static edu.corn.job.core.parser.Task.TASK;

@Data
@XmlRootElement(name = TASK)
public class Task {

    public static final String TASK = "task";

    private String name;

    private String className; // 任务执行类名称

    private Long interval;

    private String cron;

    private Long delay;

    private Long executionCount;


    // Getter 和 Setter 方法...

    public ScheduleJobProcessor createExecutor() {
        try {
            Class<?> clazz = Class.forName(className);
            return (ScheduleJobProcessor) clazz.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            throw new RuntimeException("Failed to create task executor", e);
        }
    }
}
